import sys
sys.path.append('E:\StudyTools\Eclipse\Workplace\AggPractiseAll\src\Utils')

import win32com.client as win32
import os

import uPackage

def check_win32com_exists():
    return uPackage.module_exists('win32com')


def open_excel_workbook(path, tab_name, excel_visible = False):
    if check_win32com_exists() == False:
        print 'Err: win32 package not installed'
        sys.exit()

    excel = win32.gencache.EnsureDispatch('Excel.Application')
    excel.Visible = excel_visible
    workbook = excel.Workbooks.Open(os.path.join(path))
    #excel.Workbooks.Open(r 'E:\test.xls')


def run_Excel_vba(path, tab_name, vba_name, excel_visible = False):
    if check_win32com_exists() == False:
        print 'Err: win32 package not installed'
        sys.exit()

    excel = win32.gencache.EnsureDispatch('Excel.Application')
    excel.Visible = excel_visible
    #workbook = excel.workbooks.open(path)
    #worksheet = workbook.worksheets(tab_name)

    #excel.Application.Quit()